package com.jyb.controller;

import java.util.ArrayList;
import java.util.List;

import com.jfinal.core.Controller;
import com.jyb.enumeration.ShanghaiDistrict;
import com.jyb.model.MyOrder;
import com.jyb.model.QueryLog;
import com.jyb.util.StringUtils;
import com.jyb.util.capture.GqxhUtil;
import com.jyb.vo.GqxhVo;
import com.jyb.vo.UserVo;

public class GqxhController extends Controller{

	public void index(){
		
		String tdh=getPara("tdh");
		String mt=getPara("mt");
		
		List<GqxhVo> vos=new ArrayList<GqxhVo>();
		if(!StringUtils.isEmpty(tdh)&&!StringUtils.isEmpty(mt)){
			tdh=tdh.trim();
			if("auto".equals(mt)){
				vos.addAll(GqxhUtil.capture(ShanghaiDistrict.WY, tdh));
				vos.addAll(GqxhUtil.capture(ShanghaiDistrict.WE, tdh));
				vos.addAll(GqxhUtil.capture(ShanghaiDistrict.WS, tdh));
				vos.addAll(GqxhUtil.capture(ShanghaiDistrict.WW, tdh));
				vos.addAll(GqxhUtil.capture(ShanghaiDistrict.YY, tdh));
				vos.addAll(GqxhUtil.capture(ShanghaiDistrict.YS, tdh));
			}else{
				ShanghaiDistrict district=ShanghaiDistrict.of(mt);
				vos=GqxhUtil.capture(district, tdh);
			}
		}
		
		setAttr("tdh", tdh);
		setAttr("vos", vos);
		
		UserVo userVo=(UserVo)getSession().getAttribute("user");
		if(userVo!=null){
			for (GqxhVo gqxhVo : vos) {
				MyOrder.dao.updateMyOrder(userVo.getId(), tdh, "", "");
				MyOrder.dao.updateMyOrderMt(userVo.getId(), tdh, gqxhVo.getShanghaiDistrict());
				
			}
		}
		
		if(userVo!=null&&vos.size()>0){
			QueryLog.dao.addOrUpdate(userVo.getId(), "1", tdh);
		}
		
		setAttr("nav", "gqxh");
		renderJsp("/views/gqxh/index.jsp");
	}
}
